package com.example.baselibrary.Utils;

import android.util.Patterns;
import android.webkit.URLUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class StringUtil {

    //判断字符串是否为空
    public static boolean isNullOrEmpty(String str) {
        if (str == null || str.trim().length() == 0 || str.equals("null")||str.equals("0")) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNull(String str) {
        if (str == null || str.trim().length() == 0 || str.equals("null")) {
            return true;
        } else {
            return false;
        }
    }


    //判断字符串是否是URL
    public static boolean isURL(String url) {
        if (Patterns.WEB_URL.matcher(url).matches() || URLUtil.isValidUrl(url)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isIDCard(String IDCard) {
        if (IDCard != null) {
            String IDCardRegex = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x|Y|y)$)";
            return IDCard.matches(IDCardRegex);
        }
        return false;
    }

    public static boolean isChinaPhoneLegal(String str)
            throws PatternSyntaxException {
        String regExp = "^((13[0-9])|(15[^4])|(18[0-9])|(17[0-8])|(147,145))\\d{8}$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(str);
        return m.matches();
    }

}
